package com.test.daily.leetcode.y2022.m07.day0720.v01;

import java.util.List;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/7/20 上午 09:30
 * @version: 1.0
 */
public class Solution {
    public static class Employee{
        int happy;
        List<Employee> nexts;
        public Employee(int happy, List<Employee> nexts){
            this.happy = happy;
            this.nexts = nexts;
        }
    }
    public static int maxHappy1(Employee boss){
        return process1(boss, false);
    }
    public static int process1(Employee emp, boolean canAttendee){
        if(emp == null){
            return 0;
        }
        int max = 0;
        if(canAttendee){
            for(Employee employee: emp.nexts){
                max += process1(employee, false);
            }
        } else {
            int yes = emp.happy;
            int no = 0;
            for(Employee employee: emp.nexts){
                yes += process1(employee, false);
                no += process1(employee, true);
            }
            return Math.max(yes, no);
        }
        return max;
    }

    public static class Info{
        int yes;
        int no;
        public Info(int yes, int no){
            this.yes = yes;
            this.no = no;
        }
    }
    public static int max2(Employee boss){
        Info ret = process2(boss);
        return Math.max(ret.yes, ret.no);
    }
    public static Info process2(Employee employee){
        if(employee == null){
            return new Info(0, 0);
        }
        int no = 0;
        int yes = employee.happy;
        for(Employee emp: employee.nexts){
            Info next = process2(emp);
            no += Math.max(next.no, next.yes);
            yes += next.yes;
        }
        return new Info(yes, no);
    }
}
